package com.huiqiao.lesson7.pcd;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class LogAspectClass {

    @Pointcut("within(com.huiqiao.lesson7.pcd.*)")
    public void withinScope() {}

    @Before("withinScope()")
    public void before(JoinPoint joinPoint) {
        // 获得类型
        String className = joinPoint.getTarget().getClass().getName();
        // 获得方法名
        String methodName = joinPoint.getSignature().getName();
        // 获得参数
        Object[] args = joinPoint.getArgs();
        System.out.println("Before ==> Class: " + className + ", Method: " + methodName + ", Args: " + Arrays.toString(args));
    }


//    @After("@annotation(Log)")// 这样写Log log是获取不到值的
    @After("@annotation(log)")
    public void after(JoinPoint joinPoint, Log log) {

        /// 获得类型
        String className = joinPoint.getTarget().getClass().getName();

        System.out.println(className + "执行了 ==> " + log.value());
    }
}
